package com.sharding.test.configuration;

import com.sharding.test.plugin.ShardPlugin;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.plugin.Interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.Reader;
import java.util.Properties;

@Configuration
public class Config {

    @Bean
    public Interceptor getInterceptor() throws Exception {

        Properties properties = new Properties();
        Reader reader = Resources.getResourceAsReader("shard-config.properties");
        properties.load(reader);

        Interceptor interceptor = new ShardPlugin();
        interceptor.setProperties(properties);

        return interceptor;
    }

}
